package com.dangdang.guava.collections;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.common.io.Files;

public class CollectionsDemo {

	public static void main(String[] args) {

		// 普通Collection的创建
		List<String> list = Lists.newArrayList();
		list.add("aa");
		list.add("bb");
		list.stream().forEach(e -> System.out.println(e));
		Set<String> set = Sets.newHashSet();
		Map<String, String> map = Maps.newHashMap();

		// 不变Collection的创建
		ImmutableList<String> iList = ImmutableList.of("a", "b", "c");
		// iList.add("cc");//java.lang.UnsupportedOperationException
		ImmutableSet<String> iSet = ImmutableSet.of("e1", "e2");
		ImmutableMap<String, String> iMap = ImmutableMap.of("k1", "v1", "k2", "v2");

		Multimap<String, Integer> map1 = ArrayListMultimap.create();
		map1.put("aa", 1);
		map1.put("aa", 2);
		System.out.println(map1.get("aa"));

		List<String> list2 = new ArrayList<String>();
		list2.add("aa");
		list2.add("bb");
		list2.add("cc");
		String result = Joiner.on("-").join(list2);
		System.out.println(result);

		Map<String, Integer> map2 = Maps.newHashMap();
		map2.put("xiaoming", 12);
		map2.put("xiaohong", 13);
		String result1 = Joiner.on(",").withKeyValueSeparator("=").join(map2);
		System.out.println(result1);

		File file = new File("D:\\codes\\sharding-jdbc-demo\\src\\main\\java\\com\\dangdang\\guava\\collections\\test.txt");
		List<String> list3 = null;
		try {
			list3 = Files.readLines(file, Charsets.UTF_8);
			System.out.println(list3);
		} catch (Exception e) {
			e.printStackTrace();
		}
		File to = new File("D:\\codes\\sharding-jdbc-demo\\src\\main\\java\\com\\dangdang\\guava\\collections\\test1.txt");
		try {
			Files.copy(file,to);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}  //复制文件
		
		//Files.move(new File("D:\\codes\\sharding-jdbc-demo\\src\\main\\java\\com\\dangdang\\guava\\collections\\aa")); //删除文件夹下的内容(包括文件与子文件夹)  

	}
}
